//
//  UIImageView_WebImage.swift
//  weibo
//
//  Created by wenquan wang on 12/28/16.
//  Copyright © 2016 wenquan wang. All rights reserved.
//
import SDWebImage

import Foundation

extension UIImageView{
    
    func cz_setImage(urlString: String?, placeholderImage:UIImage?, isAvatar: Bool = false){
        guard let urlString = urlString, let url = URL(string: urlString) else{
            image = placeholderImage
            return
        }
        sd_setImageWithPreviousCachedImage(with: url, placeholderImage: placeholderImage, options: [], progress: nil) {
            [weak self] (image, _, _, _) in
            if isAvatar{
                self?.image = image?.cz_avatarImage(size: self?.bounds.size)
            }
        }
    }
}
